/*
* 
 * Author: Mishal Parmar
 * Date: 27 Oct 2012
 */
package dbhandler;

import entityclasses.committee;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Mishal Parmar Date 25 Oct 2012
 */
public class CommitteeManage {

    public boolean addcommittequery(committee com) {

        String Query = "INSERT INTO `tbl_committee`(`com_id`, `com_name`) VALUES (NULL,'" + com.getCom_name() + "');";

        DBConnection db = new DBConnection();
        ResultSet rs;

        db.connect();

        try {
            db.executeQuery(Query);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();

        return true;
    }

    public ArrayList viewcommitteid(String comname) {

      
        String Query = "SELECT * FROM `tbl_committee` where `com_name`='" + comname + "';";

        DBConnection db = new DBConnection();
        ResultSet rs;
        ArrayList<committee> committearr = new ArrayList<committee>();
        db.connect();

        try {
            rs = db.customQuery(Query);

            while (rs.next()) {
                committee com = new committee();
                com.setCom_id(Integer.parseInt(rs.getString(1)));
                com.setCom_name(rs.getString(2));
                committearr.add(com);
            }


        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();

        return committearr;
    }
    
 public ArrayList viewcommitteid() {

    
        String Query = "SELECT * FROM `tbl_committee`;";

        DBConnection db = new DBConnection();
        ResultSet rs;
        ArrayList<committee> committearr = new ArrayList<committee>();
        db.connect();

        try {
            rs = db.customQuery(Query);

            while (rs.next()) {
                committee com = new committee();
                com.setCom_id(Integer.parseInt(rs.getString(1)));
                com.setCom_name(rs.getString(2));
                committearr.add(com);
            }


        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();

        return committearr;
    }
    public boolean removeCommittebyid(int id) {

        
        String Query = "DELETE FROM `tbl_committee` where `com_id`="+id;

        DBConnection db = new DBConnection();
        ResultSet rs;
        ArrayList<committee> committearr = new ArrayList<committee>();
        db.connect();

        try {
        
            
            db.executeQuery(Query);

         
         


        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        db.disconnect();

        return true;
    }

    public static void main(String args[]) {

        try {
         //   CommitteeManage c=new CommitteeManage();
        //    committee cm=new committee();
         //   ArrayList a=new ArrayList();
          // c.removeCommittebyid(8);
           //  cm=(committee)a.get(0);
        //    System.out.println(c.removeCommittebyid(8));
          
                    
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
